/**
 * @author of2470
 *@date 2017/4/1
 *@description
 */

if (!window._babelPolyfill) {
  require("babel-polyfill");
}
import * as React from "react";
import { render } from "react-dom";
import AppStore from "./store";
import { StoreProvider } from "iflux2";
import LandingPageMain from "./component/landing-page";
import "./style/landing-page.less";
import { setCookieHash } from "x-site-util";
import { Spin } from "antd";

declare let window: any;

@StoreProvider(AppStore)
export default class LandingPage extends React.Component<any, any> {
  constructor(props) {
    super(props);
    let tip = "";
    if (window.isUpdating) {
      tip = "又有新惊喜啦！建站升级中，请稍等一会儿吧～";
    }
    this.state = {
      loading: true,
      tip
    };
  }

  componentDidMount() {
    let target = this;
    //建站是否升级中
    if (window.isUpdating) {
      let dom: any = document.getElementsByClassName("ant-spin-blur");
      if (dom.length > 0) {
        dom[0].style.opacity = 0;
      }
    } else {
      this.props.store.landingPage();
      this.props.store.getActivatedPageInfo().then(
        () => {
          target.setState({ loading: false });
        },
        err => {
          console.log(err);
          target.setState({ loading: false });
        }
      );
      //把角色的hash值放在cookie里，便于建站返回控制台
      setCookieHash();
    }
  }

  render() {
    return (
      <Spin spinning={this.state.loading} tip={this.state.tip}>
        <div className="landing-page">
          <LandingPageMain />
        </div>
      </Spin>
    );
  }
}
